import { Effect , Reducer, Subscription } from 'umi';
import {getmail} from '@/services'
export interface IndexModelState {
    name: string;
    list:[],
}

export interface IndexModelType {
    namespace: 'Mail';
    state: IndexModelState;
    effects: {
        query : Effect;

    };
    reducers: {
        save: Reducer<IndexModelState>;
        // 启用 immer 之后
        // save: ImmerReducer<IndexModelState>;
    };
    subscriptions?: { setup: Subscription };
}

const AboutModel: IndexModelType = {
    namespace: 'Mail',

    state: {
        name: '',
        list:[],
    },

    effects: {

        // 获取数据
        *query({ payload }, { call, put }) {
            let request:any=[]
            yield getmail().then(res=>{
                if(res.statusCode==200){
                    request=res.data
                }
            })
            yield put({
                type:'save',
                payload:{
                    list:request
                }
            })
        },


    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
        // 启用 immer 之后
        // save(state, action) {
        //   state.name = action.payload;
        // },
    },

};

export default AboutModel;